/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.consultorio.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author L3nfers
 */
public class FabricaConexao {

    public static Connection abreConexao() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        return DriverManager.
                getConnection("jdbc:mysql://localhost:3306/consultorio", "root", "");
    }

    private static void fecha(Connection conn, Statement stmt, ResultSet rs) throws Exception {
        if (conn != null) {
            conn.close();

        }
        if (stmt != null) {
            stmt.close();
        }
        if (rs != null) {
            rs.close();
        }
    }

    public static void fechaConexao(Connection conn, Statement stmt, ResultSet rs) throws Exception {
        fecha(conn, stmt, rs);

    }

    public static void fechaConexao(Connection conn, Statement stmt) throws Exception {
        fecha(conn, stmt, null);

    }

    public static void fechaConexao(Connection conn) throws Exception {
        fecha(conn, null, null);

    }
}
